import Vue from "vue";
import App from "./App.vue";
import "./registerServiceWorker";
import router from "./router";
import store from "./store";
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import "./assets/style/reset.css";
import "./assets/style/index.less";
import directive from "@/utils/directive";
import { totalPower, powerMap } from "@/utils/powerCollection";

Vue.use(ElementUI, {
  size: 'small'
});

// 自定义指令全局注册
Object.keys(directive).forEach((name) => {
  Vue.directive(name, directive[name])
})

// 自动化注册全局基础组件
const requireComponent = require.context(
  '@/components',
  true,
  /.vue$/
)
requireComponent.keys().forEach((fileName) => {
  const componentConfig = requireComponent(fileName);
  const componentName = fileName
    .replace(/(^\.)|(\.vue)/g, '')
    .split('/').slice(1);
  if (componentName.length == 1 || componentName[1] === 'index') {
    Vue.component(componentName[0], componentConfig.default || componentConfig)
  }
});

Vue.config.productionTip = false;
Vue.prototype.$power = powerMap
Vue.prototype.$has = function (value) {
  return totalPower.includes(value);
}

new Vue({
  router,
  store,
  render: (h) => h(App)
}).$mount("#app");